<template>
	<div class="card-confirm-order-buyBtn">
		<div id="buy-btn" class="buy-btn" :class='{gogray:isGoGray}' @click="toConfirm">确认提交</div>
	</div>
</template>
<script>
	import Vue from 'vue';
	import {
		Toast
	} from 'mint-ui';
	import common from '../../utils/common.js';
	export default {
		data() {
				return {
					isGoGray: false,
					thiscarplateFull: ''
				}
			},
			props: {
				carinfo: {
					type: Object,
					default: {}
				},
				custominfo: {
					type: Object,
					default: {}
				},
				carplate: {
					type: String
				},
				carnumber: {
					type: String
				},
				storeInfo: {},
				uesrname: {
					type: String
				}
			},
			methods: {
				subMyCardData: function(carplateFull) {

					var cardSelectServer = [];
					var selectServer = JSON.parse(localStorage.cacheSeverLocalStorage);

					for(var item in selectServer) {
						cardSelectServer.push({
							quality: '1',
							skuCode: selectServer[item].skuCode
						});
					}
					
					
					var fedOrderVOString = JSON.stringify({
						packageCard: localStorage.thisCardNo,
						//结算订单商品VO 数量+skuCode
						settle: cardSelectServer,

						//订单类型   [01,线上售卡][02,普通服务][03,轮胎服务][04,洗车服务][05,套餐卡服务][06,套餐卡用卡]</p>
						orderCommitType: "06",

						//车信息 
						carModelInVo: {
							plates: this.thiscarplateFull
						},

						//到店日期        
						reservationDateStr: sessionStorage.fullday,

						//上午 下午          
						remark: '上午',

						// 联系人姓名
						contactName: this.uesrname

					});

					//console.log(this.storeinfo);
					this.$http.post(common.isdev() + '/orderFollow/orderHandle.htm', {
						fedOrderVO: fedOrderVOString
					}).then(function(d) {
						var result = JSON.parse(d.data).success;
						if(result) {
							Toast("创建订单成功");
							this.$route.router.go({
								name: 'cardpaysuccess'
							});
							localStorage.cardUesSuccessInfo = JSON.stringify({
								title: '下单成功',
								skipName: '订单详情',
								skipLink: 'mall.sit.com'
							});
						} else {
							console.log(result);
							Toast("创建订单失败");
						}

					});
				},
				toConfirm: function() {
					console.log(cardSelectServer);
					var _this = this;
					//车牌
					var carplate = '';
					var isPlate = /^[\u4e00-\u9fa5_A-Z]{1}[A-Z]{1}[A-Z_0-9]{5}$/; //车牌正则验证

					if(!_this.carinfo.disabledPlate) { //当后端没有车牌数据时
						if(this.carplate != undefined && this.carnumber != undefined) {
							this.thiscarplateFull = this.carplate.trim() + this.carnumber.trim();
							if(!isPlate.test(this.thiscarplateFull)) {
								Toast("车牌格式错误！");
								return false;
							}
						} else {
							Toast("亲，请填写车牌号！");
							return false;
						}
					} else {
						this.thiscarplateFull = _this.carinfo.carPlate;
					}

					//联系人
					var custName = '';
					if(_this.custominfo.custName) {
						custName = _this.custominfo.custName;
					} else {
						if(localStorage.getItem('username')) {
							custName = localStorage.getItem('username').trim();
						}
					}
					if(!custName) {
						Toast("亲，请填写联系人！");
						return false;
					}

					//手机
					var mobilePhone = '';
					var isMobile = /^[0-9]{11}$/;
					if(_this.custominfo.mobilePhone) {
						mobilePhone = _this.custominfo.mobilePhone;
					} else {
						if(localStorage.getItem('phone')) {
							mobilePhone = localStorage.getItem('phone').trim();
						}

					}
					if(!mobilePhone) {
						Toast("亲，请填写手机号！");

						return false;
					}
					if(!isMobile.test(mobilePhone)) {
						Toast({
							message: '亲，请填写正确的手机号！',
							duration: 125000
						});
						return;
					}
					Toast('验证成功');
					this.subMyCardData(this.thiscarplateFull);
					return true;
				}
			}
	}
</script>
<style lang="scss">
	@import "../../assets/css/_functions.scss";
	@import "../../assets/css/_variables.scss";
	@import "../../assets/css/toast.scss";	
	.card-confirm-order-buyBtn {
		font-size: rem(14);
		color: #333;
		.buy-btn {
			position: fixed;
			width: 100%;
			height: rem(48);
			background: #ff6600;
			bottom: 0;
			left: 0;
			text-align: center;
			color: #fff;
			line-height: rem(48);
			font-size: rem(18);
			&.gogray {
				background: #ccc;
			}
		}
	}
	
	.mint-toast {
		padding: rem(8)!important;
	}
</style>